#ifndef __PWLIB_LIBFILE_HPP__
#define __PWLIB_LIBFILE_HPP__

namespace purewell
{

inline
bool
__PWGetFlags(bool& chk, int fd, int flags)
{
	int _flags( fcntl(fd, F_GETFL) );
	if ( -1 == _flags ) return false;

	chk = 0 != ( _flags & flags );
	return true;
}

inline
bool
__PWSetFlags(bool set, int fd, int flags)
{
	int _flags( fcntl(fd, F_GETFL) );
	if ( -1 == _flags ) return false;

	if ( set )
	{
		_flags |= flags;
	}
	else
	{
		_flags &= ~flags;
	}

	return ( -1 != fcntl(fd, F_SETFL, _flags) );
}

inline
bool
__PWGetFDFlags(bool& chk, int fd, int flags)
{
	int _flags( fcntl(fd, F_GETFD) );
	if ( -1 == _flags ) return false;

	chk = 0 != ( _flags & flags );
	return true;
}

inline
bool
__PWSetFDFlags(bool set, int fd, int flags)
{
	int _flags( fcntl(fd, F_GETFD) );
	if ( -1 == _flags ) return false;

	if ( set )
	{
		_flags |= flags;
	}
	else
	{
		_flags &= ~flags;
	}

	return ( -1 != fcntl(fd, F_SETFD, _flags) );
}

};//namespace purewell

#endif//!__PWLIB_LIBFILE_HPP__

